package com.wenjie.controller;

import com.mybatisflex.core.query.QueryOrderBy;
import com.wenjie.original.entity.common.vo.RestBaseVo;
import com.wenjie.original.entity.table.CodeListTableDef;
import com.wenjie.original.entity.vo.CodeList.CodeListUpOrAddVo;
import com.wenjie.original.entity.vo.CodeList.CodeListVo;
import com.wenjie.original.service.ICodeListService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api("编号表")
@RestController
@RequestMapping("/api/codeList")
public class CodeListController {

    @Autowired
    private ICodeListService codeListService;

    @ApiOperation("查询接口")
    @PostMapping("/list")
    public RestBaseVo<CodeListVo.ResVo> list(@RequestBody @Validated CodeListVo.SelVo selVo) {
        QueryOrderBy desc = CodeListTableDef.CODE_LIST.CODE_LIST_ID.desc();
        QueryOrderBy[] list = {desc};
        return codeListService.list(selVo, list, CodeListVo.ResVo.class);
    }

    @ApiOperation("添加接口")
    @PostMapping("/add")
    public void add(@RequestBody @Validated CodeListUpOrAddVo.AddVo addVo) {
        codeListService.save(addVo);
    }

    @ApiOperation("修改接口")
    @PostMapping("/up")
    public void up(@RequestBody @Validated CodeListUpOrAddVo.UpVo upVo) {
        codeListService.updateById(upVo);
    }

    @ApiOperation("删除接口")
    @PostMapping("/del")
    public void del(@RequestBody @Validated Long id) {
        codeListService.removeById(id);
    }

}
